package com.ldl;

import javax.servlet.http.HttpSession;

import cn.hutool.core.util.StrUtil;

import com.ldl.exception.CodeException;

/**
 * @author Administrator
 * Author : L.D.L
 * E-mail : 1419485293@qq.com
 * Date : 2020年8月4日下午6:47:53
 */
public class Const {

    private Const(){}
	
	/**
	 * 登录用户在会话中的属性名
	 */
	public static final String LOGIN_USER_SESSION_NAME = "user";
	
	public static final String CODE_NAME = "_CODE_NAME";

	/**
	 * 验证码的服务器端验证
	 * 
	 * @param session
	 * @param code
	 * @throws CodeException
	 *             10:验证码不能为空 11:验证码已失效 12:验证码不匹配
	 */
	public static void codeVerify(HttpSession session, String code)
			throws CodeException {
		if (StrUtil.isEmpty(code)) {
			throw new CodeException(10, "验证码不能为空");
		}
		if (session.getAttribute(CODE_NAME) == null) {
			throw new CodeException(11, "验证码已失效");
		}

		if (!code.equals(session.getAttribute(CODE_NAME))) {
			throw new CodeException(12, "验证码不匹配");
		}
	}
}
